//mongodb操作文件
module.exports = function () {
    const mongoose = require('mongoose');
    mongoose.connect('mongodb://localhost:27017/supermarket',{useUnifiedTopology: true,
        useNewUrlParser: true});
    const conn = mongoose.connection;
    conn.on('connected', function () {
        console.log('【YE!!! 数据库连接成功!】')
    });

    const productSchema = mongoose.Schema({
        ID: {type: String, required: true},
        Name: {type: String, required: true},
        BIratio: {type: Number, required: true},
        BIs: {type: Array, required: true},
        tags: {type: Array, required: false},
        tip: {type: String, required: false},
        TypeandPrice: {type: Array, required: true},
        Paras: {type: Array, required: true},
        DIs: {type: Array, required: true},
    });
    this.ProductModel = mongoose.model('product', productSchema);

    this.productSave1 = function () {
        const product = {
            ID: '201616060301',
            Name: '小镇珊珊',
            BIratio: 0.75,
            BIs: ['265054620.jpg', '1320639627.jpg', '1796741959.jpg', '-1885549788.jpg'],
            tags: ['潮流穿搭', '女神新衣', '包邮', '七天无理由退换', '瘦身'],
            tip: '双11优惠大促销，店铺券满198减20，淘金币最高可抵2%！！！',
            TypeandPrice: [['橘红色', 138,666], ['米杏色', 138,892], ['深蓝色加厚', 256,577]],
            Paras: [['品牌', '小镇珊珊/SLTOWN'], ['尺码', 'S,M'], ['面料', '涤纶']],
            DIs: [{ratio: 0.3017, name: '1572412831531.jpg'},
                {ratio: 0.3175, name: '1572412880113.jpg'},
                {ratio: 0.1941, name: '1572412885374.jpg'},
                {ratio: 0.1907, name: 'l.jpg'},],
        };
        const productModel = new this.ProductModel(product);
        productModel.save(function (err, user) {
            console.log('【YE!!! 数据保存至数据库成功！】')
        })
    };



    this.productSave2 = function () {
        const product = {
            ID: '201616060302',
            Name: '美艳花礼服',
            BIratio: 1,
            BIs: ['514831531.jpg', '1183884650.jpg', '792876349.jpg', '1957445633.jpg','-2044034845.jpg'],
            tags: ['潮流穿搭', '女神新衣', '包邮', '七天无理由退换', '瘦身'],
            tip: '双11优惠大促销，店铺券满198减20，淘金币最高可抵2%！！！',
            TypeandPrice: [['橘红色', 138,158], ['米杏色', 138,166], ['深蓝色加厚', 256,258]],
            Paras: [['品牌', '小镇珊珊/SLTOWN'], ['尺码', 'S,M'], ['面料', '涤纶']],
            DIs: [{ratio: 0.696, name: '1572487723492.jpg'},
                {ratio: 0.743, name: '1572487737896.jpg'},
                {ratio: 1.116, name: '1572487741133.jpg'},
                {ratio: 0.777, name: '1572487745411.jpg'},
                {ratio: 0.664, name: '1572487748420.jpg'},],
        };
        const productModel = new this.ProductModel(product);
        productModel.save(function (err, user) {
            console.log('【YE!!! 数据保存至数据库成功！】')
        })
    };



    this.productSave3 = function () {
        const product = {
            ID: '201616060303',
            Name: 'Intel酷睿i9游戏水冷主机',
            BIratio: 0.75,
            BIs: ['1.jpg', '2.jpg', '3.jpg', '4.jpg','5.jpg'],
            tags: ['英特尔酷睿i9', '强悍性能', '包邮', '七天无理由退换', '水冷'],
            tip: '双11优惠大促销，店铺券满600减50，淘金币最高可抵2%！！！',
            TypeandPrice: [['i9高配版', 8399,10500], ['i7版', 7399,9500], ['i5低配版', 6399,7000]],
            Paras: [['品牌', '联想'], ['重量', '5Kg'], ['颜色', '黑色']],
            DIs: [{ratio: 0.645, name: '0.645.jpg'},
                {ratio: 0.645, name: '0.6451.jpg'},
                {ratio: 0.645, name: '0.6452.jpg'},
                {ratio: 0.646, name: '0.6466.jpg'},
                {ratio: 0.7579, name: '0.7579.jpg'},
                {ratio: 0.7947, name: '0.7947.jpg'},
                {ratio: 0.8144, name: '0.8144.jpg'},
            ],
        };
        const productModel = new this.ProductModel(product);
        productModel.save(function (err, user) {
            console.log('【YE!!! 数据保存至数据库成功！】')
        })
    };



    this.productSave4 = function () {
        const product = {
            ID: '201616060304',
            Name: '汤臣倍健蛋白粉',
            BIratio: 1,
            BIs: ['1.jpg', '2.jpg', '3.jpg', '4.jpg'],
            tags: ['假一赔四', '急速退款', '包邮', '七天无理由退换', '一站式购齐'],
            tip: '双11优惠大促销，店铺券满600减50，淘金币最高可抵2%！！！',
            TypeandPrice: [['1罐', 308,338], ['2罐', 585,650], ['3罐', 800,960]],
            Paras: [['品牌', '汤臣倍健'], ['重量', '450g']],
            DIs: [{ratio: 1.4285, name: '11.4285.jpg'},
                {ratio: 1.4285, name: '21.4285.jpg'},
                {ratio: 0.9272, name: '30.9272.jpg'},
                {ratio: 0.632, name: '40.632.jpg'},
                {ratio: 0.632, name: '50.632.jpg'},
                {ratio: 0.632, name: '60.632.jpg'},
                {ratio: 0.632, name: '70.632.jpg'},
                {ratio: 0.632, name: '80.632.jpg'},
                {ratio: 0.632, name: '90.632.jpg'},
                {ratio: 0.632, name: '100.632.jpg'},
                {ratio: 0.1965, name: '110.1965.jpg'},
            ],
        };
        const productModel = new this.ProductModel(product);
        productModel.save(function (err, user) {
            console.log('【YE!!! 数据保存至数据库成功！】')
        })
    };




};

